<?php
/**
 * +----------------------------------------------------------------------
 * | 流媒体接口
 * +----------------------------------------------------------------------
 *                      _ooOoo_
 *                     o8888888o            | AUTHOR: 杜云
 *                     88" . "88            | EMAIL: 987772927@qq.com
 *                     (| -_- |)            | QQ: 987772927
 *                     O\  =  /O            | WECHAT: 987772927
 *                  ____/`---'\____
 *                .'  \\|     |//  `.
 *               /  \\|||  :  |||//  \
 *              /  _||||| -:- |||||-  \
 *              |   | \\\  -  /// |   |
 *              | \_|  ''\-/''  |   |
 *              \  .-\__  `-`  ___/-. /
 *            ___`. .'  /-.-\  `. . __
 *         ."" '<  `.___\_<|>_/___.'  >'"".
 *        | | :  `- \`.;`\ _ /`;.`/ - ` : | |
 *        \  \ `-.   \_ __\ /__ _/   .-` /  /
 *   ======`-.____`-.___\_____/___.-`____.-'======
 *                      `=-='
 * +----------------------------------------------------------------------
 */
declare(strict_types=1);
namespace App\Service;

use Hyperf\Guzzle\ClientFactory;

class StreamingMediaService
{
    /**
     * @var \Hyperf\Guzzle\ClientFactory
     */
    private $clientFactory;
    
    public function __construct(ClientFactory $clientFactory)
    {
        $this->clientFactory = $clientFactory;
    }
    public function handle(string $method = 'GET',string $api = '', array $param = [])
    {
        // $options 等同于 GuzzleHttp\Client 构造函数的 $config 参数
        $options = [
            'base_uri' => 'http://127.0.0.1:8080/',
            'timeout'         => 0,
            'allow_redirects' => false,
            'verify' => false,
        ];
        var_dump($param);
        // $client 为协程化的 GuzzleHttp\Client 对象
        $client = $this->clientFactory->create($options);
        try {
            $res = $client->request($method, $api,$param);
            return ['status'=>true,'msg'=>'请求成功','data'=>json_decode($res->getBody()->getContents(),true)?:[]];
        } catch (\Exception $e) {
            return ['status'=>false,'msg'=>'请求错误:'.$e->getMessage(),'data'=>[]];
        }
    }
}
